package com.zyx.javademo.exception;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author Yaxi.Zhang
 * @since 2021/9/28 17:54
 * desc: execute UncaughtExceptionHandler捕获异常失败
 * reference: https://honeypps.com/java/java-multi-thread-of-uncaught-exception-handler/
 * 参考 {@link InitiativeCaught} {@link WitchCaughtThread}
 * 如果直接采用线程池通过execute的方法去捕获异常, 仍会报错
 */
public class ExecuteCaught {
    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();
        Thread thread = new Thread(new Task());
        thread.setUncaughtExceptionHandler(new ExceptionHandler());
        exec.execute(thread);
        exec.shutdown();
    }
}
